package com.example.vue20220402.pojo;

import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResult implements Serializable {
    public static final int STATUS_SUCCESS = 200;
    public static final int STATUS_FALL = 500;
    private int status;//返回状态码
    private String message;//返回信息
    private Object result;//返回数据
    //返回时间
    private long timestamp = System.currentTimeMillis();

    public static BaseResult createResult(int status, String message, Object result){
        return new BaseResult(status,message,result);
    }

    public static BaseResult success(){
        return new BaseResult(STATUS_SUCCESS,"成功",null);
    }
    public static BaseResult success(String message){
        return new BaseResult(STATUS_SUCCESS,message,null);
    }
    public static BaseResult success(Object result){
        return new BaseResult(STATUS_SUCCESS,"成功",result);
    }
    public static BaseResult success(String message,Object result){
        return new BaseResult(STATUS_SUCCESS,message,result);
    }
    public static BaseResult fail(){
        return new BaseResult(STATUS_FALL,"失败",null);
    }
    public static BaseResult fail(String message){
        return new BaseResult(STATUS_SUCCESS,message,null);
    }
    public static BaseResult fail(Object result){
        return new BaseResult(STATUS_SUCCESS,"成功",result);
    }
    public static BaseResult fail(String message,Object result){
        return new BaseResult(STATUS_SUCCESS,message,result);
    }

    public BaseResult(int status, String message, Object result, long timestamp) {
        this.status = status;
        this.message = message;
        this.result = result;
        this.timestamp = timestamp;
    }

    public BaseResult(int status, String message, Object result) {
        this.status = status;
        this.message = message;
        this.result = result;
    }
}
